using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DataListAndDropDownList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            FillRecruiterAccount(this.DataList1,"1");
    }
    void FillRecruiterAccount(DataList DataList1, string Province)
    {
        try
        {
            SqlDataSource sqlDataSource = new SqlDataSource();
            sqlDataSource.ConnectionString =
            WebConfigurationManager.ConnectionStrings[
                "RecruitVietnamDbConnectionString"
                ].ConnectionString;
            sqlDataSource.SelectCommandType =
            SqlDataSourceCommandType.Text;
            sqlDataSource.SelectCommand = "select " +
            "RecruiterID, Email,CompanyName,"
            + "ContactName,  Address,Phone" +
            " from tblRCAccounts where "
            +" ProvinceID='" + Province +"'";            
             
            DataList1.DataKeyField= "RecruiterID";
            DataList1.DataSource  = sqlDataSource;
            DataList1.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        FillRecruiterAccount(this.DataList1, DropDownList1.SelectedValue);
    }
}
